package com.example.textswitchtestdemo01.util;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.example.textswitchtestdemo01.R;

public class InitToolbar {

    public static void initToolbar(final AppCompatActivity activity, String title, boolean homeAsUpEnabled) {
        TextView tv_title = (TextView) activity.findViewById(R.id.tv_title);
        Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
        tv_title.setText(title);
        if (title.equals("第七页")) {
            ImageView shopimg = activity.findViewById(R.id.img_shop);
            shopimg.setVisibility(View.VISIBLE);
        }
        activity.setSupportActionBar(toolbar);
        activity.getSupportActionBar().setTitle("");
        activity.getSupportActionBar().setDisplayHomeAsUpEnabled(homeAsUpEnabled);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.finish();
            }
        });
    }

}
